package com.tianqu.tms.core.util;

import java.io.File;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;

/**
 * �ַ��?ͬ��
 * 
 * @author liugang
 *
 */
public class StringUtil implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/** Automatically generated javadoc for: ASCIINUMBER */
	private static final int ASCIINUMBER = 0xFF00;

	private static String DATE_DEFAULT = "9999-12-31";

	// UNABLE TO XML PARSE CHAR SET
	public static final char UN_XML_CHAR_SET[] = { '' };
	public static final char TARGET_CHAR = ' ';

	/**
	 * ���纯��
	 */
	private StringUtil() {
		super();
	}

	/**
	 * SQL�Ľ������л�ʹ��<br />
	 * ex: escapeSingleQuotation("'abc'de'fg'h'") --> [''abc''de''fg''h'']<br />
	 * 
	 * @param value
	 * @return String
	 * @since A001
	 */
	public static String escapeSingleQuotation(String value) {

		if (value == null) {
			return "";
		}
		StringBuffer sb = new StringBuffer();
		int len = value.length();
		int pos = 0;
		while (value.substring(pos, len).indexOf("'") > -1) {
			int endpos = value.indexOf("'", pos) + 1;
			sb.append(value.substring(pos, endpos) + "'");
			pos = endpos;
		}
		sb.append(value.substring(pos, len));
		return sb.toString();
	}

	public static String escapeSingleQuotations(String value) {

		if (value == null) {
			return "";
		} else {
			return value;
		}

	}

	/**
	 * 
	 * @param field
	 * @return
	 */
	public static String addSqlQuot(String field) {
		String str = field;
		if (str == null) {
			str = "";
		}
		return "'" + StringUtil.escapeSingleQuotation(str) + "'";
	}

	/**
	 * �ַ�trim����<BR>
	 * 
	 * @param str
	 * @return null��ʱ�򷵻�"" ��null��ʱ�����trim����
	 */
	public static String triming(String input) {
		if (input == null || "null".equals(input)) {
			return "";
		}
		return input.trim();

	}

	/**
	 * if string is null or length is 0 return true, else false
	 * </p>
	 * <br />
	 */
	public static boolean isNotBlank(String str) {
		return !isNullOrBlank(str);
	}

	public static boolean isNullOrBlank(String str) {
		if(str == null || "".equals(str)) return true;
		else return false;
	}

	/**
	 * ����ַ����ʵ��С ex: "����2" -> length=5
	 *
	 * @param str
	 * @return int
	 */
	public static int getTrueLength(String str) {
		if (str == null || str.length() == 0) {
			return 0;
		}
		int length = 0;
		try {
			length = str.getBytes("GBK").length;
		} catch (java.io.UnsupportedEncodingException e1) {
		}
		return length;
	}

	/**
	 * ɾ�������е�comma(,)<��ҪӦ����Ǯ> ex��123,123 -> 123123
	 * 
	 * @param string
	 * @return
	 */
	public static String delMoneyComma(String string) {
		String ret = "";
		if (string == null)
			return ret;
		String str = string.trim();
		int length = str.length();

		for (int i = length; i > 0; i--) {
			String achar = str.substring(length - i, length - i + 1);
			if (!achar.equals(",")) {
				ret = ret + achar;
			}
		}
		return ret;
	}

	/**
	 * ����ÿ����λ׷��comma(',')<��ҪӦ����Ǯ> ex��1123123 -> 1,123,123
	 * 
	 * @param string
	 * @return
	 */
	public static String addMoneyComma(String string) {
		String ret = "";
		if (string == null)
			return ret;
		String str = string.trim();
		int length = str.length();
		if (!isDigit(str))
			return str;

		for (int i = length; i > 0; i--) {
			String achar = str.substring(length - i, length - i + 1);
			ret = ret + achar;
			if (((i - 1) % 3) == 0 && i != 1)
				ret = ret + ",";
		}
		return ret;
	}

	/**
	 * ��С��������ÿ����λ׷��comma(',')<��ҪӦ����Ǯ> ex��1123123.01 -> 1,123,123.01
	 * 
	 * @param string
	 * @return
	 */
	public static String addMoneyPeriodComma(String string) {
		String ret = "";
		if (string == null || string.trim().length() == 0)
			return ret;
		String str = string.trim();
		boolean flag = false;
		int length = str.length();
		String strFlag = "";
		int lPeriod = string.lastIndexOf(".");

		String sAfter = "";
		if (lPeriod != -1) {
			sAfter = string.substring(lPeriod, length);

			strFlag = string.substring(0, 1);
			if ("+".equals(strFlag) || "-".equals(strFlag)) {
				flag = true;
				str = string.substring(1, lPeriod);
			} else {
				str = string.substring(0, lPeriod);
			}
			length = str.length();
		}
		if (!isDigit(str))
			return str;
		for (int i = length; i > 0; i--) {
			String achar = str.substring(length - i, length - i + 1);
			ret = ret + achar;
			if (((i - 1) % 3) == 0 && i != 1)
				ret = ret + ",";
		}
		if (flag) {
			return strFlag + ret + sAfter;
		}
		return ret + sAfter;
	}

	/**
	 * �����������루ֻ����2λС��,��ʽ��0.##��
	 * 
	 * @param v
	 *            ��Ҫ���������
	 * @param scale
	 *            ָ����������ֺ����м�λС��
	 * @return
	 */
	public static String round(double v, int scale) {
		BigDecimal b = new BigDecimal(Double.toString(v));
		BigDecimal one = new BigDecimal("1");
		String strNum = "";
		double dou;
		if (scale == 0) {
			dou = v;
		} else {
			dou = b.divide(one, scale, BigDecimal.ROUND_HALF_UP).doubleValue();
		}
		if (dou == 0) {
			strNum = String.valueOf(dou);
		} else {
			DecimalFormat df = new DecimalFormat("0.##");
			strNum = df.format(dou);
		}

		return strNum;
	}

	/**
	 * �ж�������(��С��㲻�У�
	 * 
	 * @param s
	 *            String
	 * @return boolean
	 * 
	 */
	public static boolean isDigit(String s) {
		for (int i = 0; i < s.length(); i++) {
			if (!isDigit(s.charAt(i))) {
				return false;
			}
		}
		return true;
	}

	/**
	 * ����check
	 * 
	 * @param c
	 *            char
	 * @return boolean
	 * 
	 */
	public static boolean isDigit(char c) {
		return (isAscii(c) && Character.isDigit(c));
	}

	/**
	 * Ӣ����ĸcheck
	 * 
	 * @param c
	 *            char
	 * @return boolean
	 */
	public static boolean isAscii(char c) {
		return ((c & ASCIINUMBER) >> 8 == 0);
	}

	/**
	 * �ж��ַ�����ǲ���Ǯ
	 * 
	 * @param string
	 * @return
	 */
	public static boolean isRightMoney(String string) {
		String ret = "";
		if (string == null)
			return true;
		String str = string.trim();
		int length = str.length();
		boolean flag = true;

		for (int i = length; i > 0; i--) {
			String achar = str.substring(length - i, length - i + 1);
			if (achar.equals(",")) {
				flag = false;
			} else {
				ret = ret + achar;
			}
		}
		String str1 = addMoneyComma(ret);
		if (str.equals(str1) || flag)
			return true;
		else
			return false;
	}

	/**
	 * �ַ����׷��ָ���Ŀո�
	 * 
	 * @param before
	 * @param size
	 * @return
	 */
	public static String appendBlank(String before, int size) {

		StringBuffer ret = new StringBuffer();
		String BLANK = " ";
		int addCount = 0;
		String copy = before;

		if (copy == null) {
			copy = "";
		}

		if (copy.length() >= size) {
			return before;
		}

		ret.append(copy);
		addCount = size - copy.length();

		while (addCount > 0) {
			ret.append(BLANK);
			addCount--;
		}

		return ret.toString();

	}

	/**
	 * �滻<br>
	 * 
	 * @param str
	 * @return
	 */
	public static String replaceBr(String str) {

		int i;
		int strStart = 0;
		int strEnd = 0;
		for (i = 0; str.length() - 1 >= i; i++) {
			if (str.charAt(i) == '<') {
				strStart = i;
			}
			if (str.charAt(i) == '>') {
				strEnd = i + 1;
			}
		}
		if (strEnd == 0) {
			return str;

		} else {

			return str.substring(0, strStart) + str.substring(strEnd, str.length());

		}
	};

	public static String replaceAll(String source, String regex, String replacement) {
		if (source == null || regex == null || replacement == null)
			return null;
		String tempSource = source;
		boolean isOK = tempSource.indexOf(regex) < 0;
		while (!isOK) {
			int pBegin = tempSource.indexOf(regex);
			String sBefore = tempSource.substring(0, pBegin);
			String sAfter = tempSource.substring(pBegin + regex.length());
			tempSource = sBefore + replacement + sAfter;
			isOK = tempSource.indexOf(regex) < 0;
		}
		return tempSource;
	}

	/**
	 * ����ת��Ϊ�ַ�
	 * 
	 * @param obj
	 * @return
	 */
	public static String objToString(Object obj) {
		if (obj != null) {
			return obj.toString().trim();
		} else {
			return "";
		}
	}

	/**
	 * listת��Ϊ��','�ָ���ַ�
	 * 
	 * @param list
	 * @return
	 */
	public static String listToArrayString(List list) {
		if (list == null || list.isEmpty())
			return "";
		StringBuffer buffer = new StringBuffer();
		for (int i = 0; i < list.size(); i++) {
			if (buffer.length() > 0)
				buffer.append(",");
			buffer.append(list.get(i));
		}
		return buffer.toString();
	}

	/**
	 * ȡ��ָ����ʼλ�õ��ַ�<br>
	 *
	 * @param str
	 *            �ַ�
	 * @param beginIndex
	 *            ��ʼλ��
	 * @return
	 */
	public static String getSubString(String str, int beginIndex) {
		String subStr = "";
		if (beginIndex < 0) {
			return subStr;
		}
		if (str != null && beginIndex < str.length()) {
			subStr = str.substring(beginIndex);
		}
		return subStr;
	}

	/**
	 * ȥ����ʼλ�úͽ���λ�õ��ַ�<br>
	 *
	 * @param str
	 * @param beginIndex
	 * @param endIndex
	 * @return
	 */
	public static String getSubString(String str, int beginIndex, int endIndex) {
		String subStr = "";
		if (beginIndex < 0 || endIndex < 0 || endIndex < beginIndex) {
			return subStr;
		}
		if (str != null && beginIndex < str.length()) {
			if (str.length() < endIndex) {
				subStr = str.substring(beginIndex);
			} else {
				subStr = str.substring(beginIndex, endIndex);
			}
		}
		return subStr;
	}

	/**
	 * �ַ���д<br>
	 *
	 * @param str
	 * @return
	 */
	public static String toUpperCase(String str) {
		if (str != null && 0 < str.length()) {
			str = str.toUpperCase();
		}
		return str;
	}

	/**
	 * ������д<br>
	 *
	 * @param strArray
	 * @return
	 */
	public static String[] upperCaseArray(String[] strArray) {
		if (strArray == null || strArray.length == 0) {
			return strArray;
		}
		for (int i = 0; i < strArray.length; i++) {
			if (strArray[i] != null && 0 < strArray[i].length()) {
				strArray[i] = strArray[i].toUpperCase();
			}
		}
		return strArray;
	}

	/**
	 * 
	 * @param date
	 * @return
	 */
	public static String filterDate(String date) {
		if (date == null) {
			return "";
		} else if (date.replaceAll("/", "-").equals(DATE_DEFAULT)) {
			return "";
		}
		return date;
	}

	/**
	 * 
	 * @param partNo
	 * @return
	 */
	public static String fillPartNo(String partNo) {
		if (partNo == null || partNo.length() == 0) {
			return partNo;
		}
		for (int i = partNo.length(); i < 8; i++) {
			partNo = "0" + partNo;
		}
		return partNo;
	}

	/**
	 * 
	 * @param partNos
	 * @return
	 */
	public static String[] fillPartNoArray(String[] partNos) {
		if (partNos == null || partNos.length == 0) {
			return partNos;
		}
		for (int i = 0; i < partNos.length; i++) {
			partNos[i] = fillPartNo(partNos[i]);
		}
		return partNos;
	}

	/**
	 * 
	 * @param value
	 * @return
	 */
	public static int stringToInt(String value) {
		if (isNullOrBlank(value)) {
			return 0;
		} else {
			return Integer.parseInt(value);
		}
	}

	/**
	 * 
	 * @param value
	 * @param length
	 * @return
	 */
	public static String fillZeroFromLeft(String value, int length) {
		if (value == null || value.length() >= length) {
			return value;
		}
		length = length - value.length();

		for (int i = 0; i < length; i++) {
			value = "0".concat(value);
		}
		return value;
	}

	/**
	 * 
	 * @param input
	 * @return
	 */
	public static String filterToHtml(String input) {
		if (input == null || input.equals("")) {
			return input;
		}
		StringBuffer filtered = new StringBuffer(input.length());
		char c;
		for (int i = 0; i <= input.length() - 1; i++) {
			c = input.charAt(i);
			switch (c) {
			case 13:
				filtered.append("<br />");
				break;
			default:
				filtered.append(c);
			}
		}
		return (filtered.toString());
	}

	/**
	 * 获取当前系统时间一个月前的时间
	 * 
	 * @return
	 */
	public static String lastMonthTime() {

		Date date = new Date();// 当前日期
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");// 格式化对象
		Calendar calendar = Calendar.getInstance();// 日历对象
		calendar.setTime(date);// 设置当前日期
		calendar.add(Calendar.MONTH, -1);// 月份减一

		return sdf.format(calendar.getTime());
	}

	/**
	 * @param date
	 * @return yyyy-MM-dd HH:mm
	 * @throws ParseException
	 */
	public static Date getCurrDateTimeNotSec(Date date) throws ParseException {
		String rtn = "";
		// Date today = new Date();
		SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		rtn = fm.format(date);
		Date ddd = fm.parse(rtn);
		return ddd;
	}

	/**
	 * 截取double类型小数点后一位
	 * 
	 * @param dou
	 * @return
	 */
	public static double getDoubleStyle(Double dou) {
		DecimalFormat df = new DecimalFormat(".#");
		String st = df.format(dou);
		return Double.parseDouble(st);
	}

	/**
	 * 去0
	 */
	public static String getString(int num) {
		if (num < 1) {
			return "";
		} else {
			return String.valueOf(num);
		}
	}

	/**
	 * 加0
	 */
	public static int getint(String num) {
		if (isNullOrBlank(num)) {
			return 0;
		} else {
			return Integer.valueOf(num);
		}
	}

	/**
	 * 将排期量毫升转换成升
	 * 
	 */
	public static String getNewExhaust(int exhaust) {
		String str = "";
		double cc = Double.parseDouble(String.valueOf(exhaust));
		if (exhaust > 0) {
			cc = cc / 1000;
			str = String.valueOf(cc);
			str = str.substring(0, str.indexOf(".") + 2) + "L";
			return str;
		}
		return str;
	}

	/**
	 * 将排期量毫升转换成升
	 * 
	 */
	public static String getNewExhaust1(int exhaust) {
		String str = "";
		double cc = Double.parseDouble(String.valueOf(exhaust));
		if (exhaust > 0) {
			cc = cc / 1000;
			str = String.valueOf(cc);
			str = str.substring(0, str.indexOf(".") + 2);
			return str;
		}
		return str;
	}

	/**
	 * 获取场次开始时间节点
	 * 
	 * @return
	 */
	public static String getstartTime() {

		Calendar c = Calendar.getInstance();// 可以对每个时间域单独修改
		int minute = c.get(Calendar.MINUTE);
		if (minute >= 0 && minute <= 30) {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:00");// 设置日期格式
			return df.format(new Date());
		} else if (minute > 30 && minute <= 60) {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:30");// 设置日期格式
			return df.format(new Date());
		}
		return null;
	}

	/**
	 * 获取场次结束时间节点
	 * 
	 * @return
	 */
	public static String getendTime() {

		Calendar c = Calendar.getInstance();// 可以对每个时间域单独修改
		int minute = c.get(Calendar.MINUTE);
		if (minute >= 0 && minute <= 30) {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:30");// 设置日期格式
			return df.format(new Date());
		} else if (minute > 30 && minute <= 60) {
			SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:60");// 设置日期格式
			return df.format(new Date());
		}
		return null;
	}

	/**
	 * 获得列表页面显示时间段
	 * 
	 * @return
	 */
	public static String getBidStartTime() {
		Calendar c = Calendar.getInstance();// 可以对每个时间域单独修改
		int minute = c.get(Calendar.MINUTE);
		if (minute >= 0 && minute <= 30) {
			SimpleDateFormat df = new SimpleDateFormat("HH:00");// 设置日期格式
			return df.format(new Date());
		} else if (minute > 30 && minute <= 60) {
			SimpleDateFormat df = new SimpleDateFormat("HH:30");// 设置日期格式
			return df.format(new Date());
		}
		return "0";
	}

	/**
	 * 1.保留小数点后两位 2.非四舍五入 3.精确值：百位
	 * 
	 * @param yuan
	 * @return
	 */
	public static String transYtoW(int yuan) {
		String str = "";
		if (yuan > 0) {
			double b = (double) (yuan / 10000.0);
			DecimalFormat df = new DecimalFormat("0.000");
			String db = df.format(b);
			int num = db.indexOf(".");
			return db.substring(0, num) + db.substring(num, num + 3);
		}
		return str;
	}

	/**
	 * 1.保留小数点后一位或者两位 2.非四舍五入 3.精确值：千位或者百位
	 * 
	 * @param yuan
	 * @return
	 */
	public static String transYtoW1(int yuan) {
		String str = "";
		if (yuan > 0) {
			double b = (double) (yuan / 10000.0);
			DecimalFormat df = new DecimalFormat("0.000");
			String db = df.format(b);
			int num = db.indexOf(".");
			if (num == 3) {
				return db.substring(0, num) + db.substring(num, num + 2);
			} else {
				return db.substring(0, num) + db.substring(num, num + 3);
			}

		}
		return str;
	}

	/**
	 * 1.保留小数点后一位 2.非四舍五入
	 * 
	 * @param num
	 * @return
	 */
	public static String transOnes(int num1) {
		String str = "";
		if (num1 > 0) {
			double b = (double) (num1 / 1000.0);
			DecimalFormat df = new DecimalFormat("0.000");
			String db = df.format(b);
			int num = db.indexOf(".");
			return db.substring(0, num) + db.substring(num, num + 2);
		}
		return str;
	}

	public static String getBidStatus(int num) {
		switch (num) {
		case 1:
			// 竞价管理修正 Start
			return "等待竞价";
		case 2:
			return "竞价中";
		case 3:
			return "竞价结束";
		case 4:
			return "成交";
		case 5:
			return "流拍";
		case 6:
			return "回访成交";// 增加（回访成交） modify by mufeiyu
		default:
			return "";
		}
	}

	public static String getBidType(int num) {
		switch (num) {
		case 1:
			return "寻价模式";
		default:
			return "";
		}
	}
	// 竞价管理修正 End

	/**
	 * 将万转换成元
	 */
	public static int transWtoY(String wan) {
		int pp = 0;
		double w = Double.parseDouble(wan);
		w = w * 10000;
		if (w > 0) {
			pp = Integer.parseInt(new java.text.DecimalFormat("0").format(w));
		}
		return pp;
	}

	/**
	 * 将升转换成毫升
	 */
	public static int transWtoY1(String wan) {
		int pp = 0;
		double w = Double.parseDouble(wan);
		w = w * 1000;
		if (w > 0) {
			pp = Integer.parseInt(new java.text.DecimalFormat("0").format(w));
		}
		return pp;
	}

	/**
	 * cvs文件数据转型
	 * 
	 * @param value
	 * @return
	 */
	public static int Source(String value) {
		if (value != null && !"".equals(value)) {
			value = value.trim();
			if (value.equals("车集网")) {
				return 1;
			} else if (value.equals("TAS")) {
				return 2;
			}
		}
		return 0;
	}

	/**
	 * 如果为空返回空字符串
	 * 
	 * @param str
	 * @return
	 */
	public static String isNULL(String str) {
		if (str == null || "".equals(str)) {
			return "";
		} else {
			return str;
		}
	}

	/**
	 * 根据tempstap转换成String类型
	 */
	/**
	 * TimeStamp-->String
	 * 
	 * @param timeS
	 * @return
	 */
	public static String getTimeByTimeStamp(Timestamp timeS) {
		if (timeS != null) {
			SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			return fm.format(timeS);

		} else {
			return null;
		}

	}

	/**
	 * 根据tempstap转换成String类型
	 */
	/**
	 * TimeStamp-->String
	 * 
	 * @param timeS
	 * @return
	 */
	public static String getTimeByTimeStamps(Timestamp timeS) {
		if (timeS != null) {
			SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			return fm.format(timeS);

		} else {
			return null;
		}

	}

	public static boolean isNumeric(String v) {
		return StringUtils.isNumeric(v);
	}

	/**
	 * 如果数据未none则修改为空字符串
	 */
	public static String getNone(String NONE) {
		String st = triming(NONE);
		if (st.equals("NONE")) {
			return "";
		} else {
			return st;
		}
	}

	/**
	 * 如果数据为none则修改为空字符串
	 */
	public static int getNoneber(String NONE) {
		String st = triming(NONE);
		if (st.equals("NONE")) {
			return 0;
		} else if (st.equals("")) {
			return 0;
		} else {
			return Integer.valueOf(st);
		}
	}

	public static double getDouble(String NONE) {
		if (NONE != null && !"NONE".equals(NONE) && !"".equals(NONE.trim())) {
			return Double.valueOf(NONE);
		}
		return 0.00;
	}

	/**
	 * 
	 * 车辆使用年限比较
	 * 
	 * @param dateStr
	 * @return
	 */

	public static int getCarYear(String dateStr) {

		SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if (dateStr != null && dateStr.length() > 0) {
			if (dateStr.length() == 10) {
				fm = new SimpleDateFormat("yyyy-MM-dd");
			} else if (dateStr.length() == 16) {
				fm = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			} else if (dateStr.length() == 7) {
				fm = new SimpleDateFormat("yyyy-MM");
			} else if (dateStr.length() == 6) {
				fm = new SimpleDateFormat("yyyy-M");
			}
		} else {
			return 0;
		}

		try {
			Date day = new Date();
			long moonthValue = (day.getTime() - fm.parse(dateStr).getTime()) / (1000l * 60 * 60 * 24 * 30);
			if (moonthValue > 0) {
				if (moonthValue % 12 > 0) {
					return (int) (moonthValue / 12 + 1);
				} else {
					return (int) (moonthValue / 12);
				}

			} else if (moonthValue == 0) {
				return 1;
			}
		} catch (ParseException e) {
			e.printStackTrace();
			return 3;
		}
		return 3;
	}

	/**
	 * 空值和“-”转换
	 * 
	 */
	public static String transNullStr(String str) {
		if ("".equals(str) || str == null) {
			return "-";
		}

		return str;
	}

	/**
	 * 空值和“-”转换
	 * 
	 */
	public static String transNullStrNull(String str) {

		if (str == null || "".equals(str))
			return "";

		return str;
	}

	/**
	 * 空值和“-”转换
	 * 
	 */
	public static String transNullintNull(Integer str) {
		int i = str;
		if (str == 0)
			return "";

		return String.valueOf(i);
	}

	/**
	 * “”返回“无” 1 返回“轻微” 2 返回严重
	 */
	public static String transIntLevelToStr(int level) {
		if (level == 0) {
			return "无";
		}
		if (level == 1) {
			return "轻微";
		}
		if (level == 2) {
			return "严重";
		}
		return "";
	}

	/**
	 * 1 转换成“是” 2 转换成“否”
	 * 
	 * @param str
	 * @return
	 */
	public static String transIntLevelToStr2(int level) {
		if (level == 1) {
			return "是";
		} else if (level == 2) {
			return "否";
		}
		return "";
	}

	/**
	 * 及检测报告字符串截取
	 * 
	 * 空则返回“” 不空则截取前两位
	 * 
	 */
	public static String subStrTool(String str) {
		if ("-".equals(str) || str == null || "".equals(str)) {
			return "";
		} else {
			if (str.length() == 2) {
				return str;
			} else if (str.length() == 3) {

				return str.substring(0, 2);
			}
		}

		return str;
	}

	/**
	 * 截取检测程度tool
	 */
	public static String subStrTool2(String str) {
		if ("-".equals(str) || str == null || "".equals(str)) {
			return "";
		} else {
			if (str.length() == 2) {
				return "";
			} else if (str.length() == 1) {
				return str;
			} else if (str.length() == 3) {
				return str.substring(2, 3);
			}
			return str;
		}
	}

	/**
	 * 检测模式切换
	 * 
	 */
	public static String getCheckModel(int exhaust) {

		switch (exhaust) {
		case 1:

			return "基本检测";
		case 2:

			return "高级检测";
		default:
			break;
		}

		return "";
	}

	/**
	 * 如果数据为none则修改为空字符串
	 */
	public static int getNoneber2(String NONE) {
		String st = triming(NONE);
		if (st.equals("NONE")) {
			return 0;
		} else if (st.equals("")) {
			return 0;
		} else if (st.equals("0")) {
			return 2;
		} else {
			return Integer.valueOf(st);
		}
	}

	/**
	 * 将int型小数三个一隔开
	 * 
	 * @param args
	 */
	public static String getPointBetweenThree(int yy) {
		DecimalFormat df2 = new DecimalFormat("#,###");
		return df2.format(yy);
	}

	/**
	 * 去掉逗号
	 * 
	 * @param args
	 */
	public static String removeDH(String str) {
		if (str != null && !"".equals(str)) {
			return str.replaceAll(",", "");
		}
		return "";
	}

	/***
	 * 
	 * 三位一个逗号
	 * 
	 * @param args
	 */
	public static String addDH(String str) {
		if (str != null && !"".equals(str)) {
			str = new StringBuilder(str).reverse().toString(); // 先将字符串颠倒顺序
			String str2 = "";
			for (int i = 0; i < str.length(); i++) {
				if (i * 3 + 3 > str.length()) {
					str2 += str.substring(i * 3, str.length());
					break;
				}
				str2 += str.substring(i * 3, i * 3 + 3) + ",";
			}
			if (str2.endsWith(",")) {
				str2 = str2.substring(0, str2.length() - 1);
			}
			// 最后再将顺序反转过来
			return new StringBuilder(str2).reverse().toString();
		}

		return "";
	}

	public static String addDH(int str) {
		DecimalFormat df = new DecimalFormat("###,###,###,###,###");
		return df.format(str);
	}
	
	public static String filterNull(String v) {
		if (v == null)
			return "";
		else
			return v;
	}

	public static boolean isInteger(String str) {
		try {
			new Integer(str);
		} catch (Exception e) {
			return false;
		}
		return true;
	}
	 
	public static boolean isNumber(String str) {
		if (StringUtil.isNullOrBlank(str))
			return false;
		try {
			new BigDecimal(str);
		} catch (Exception e) {
			return false;
		}
		return true;
	}
	
	public static boolean isEmpty(String s) {
		return s == null || s.length() == 0;
	}
	
	public static String formatCarName (String s) {
		if(StringUtils.isBlank(s)) return "";
		int index = s.lastIndexOf("(");
		if(index >0) return s.substring(0, index);
		return s;
	}
	
}
